<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            position: relative;
            margin: 50px auto;
            width: 512px;
            height: 400px;
            border: 1px solid #000000;
            /* 超出部分隐藏 */
            overflow: hidden;
        }

        .box>img {
            position: absolute;
            top: 0px;
            left: 0px;
        }

        .box>span {
            position: absolute;
            left: 0px;
            width: 100%;
            height: 200px;
            cursor: pointer;
        }

        .box>span#up {
            top: 0;
        }

        .box>span#down {
            bottom: 0;
        }
    </style>
</head>
<script>
    window.onload = function () {
        function $(selecter) {
            return document.querySelector(selecter)
        }
        var moveVal = 0;
        var timer = null;
        $('#up').onmouseover = function () {
            clearInterval(timer)
            timer = setInterval(() => {
                moveVal-=3;
                if(moveVal<=-1070){
                    clearInterval(timer)
                }else{
                    $('img').style.top=moveVal+'px'
                }

            },50)
        }
        $('#down').onmouseleave = function () {
            clearInterval(timer)
            timer = setInterval(() => {
                moveVal+=3;
                if(moveVal<0){
                    $('img').style.top=moveVal+'px'
                }else{
                    clearInterval(timer)
                }
            },50)
        }

    }
</script>

<body>
    <div class="box">
        <img src="./mi.png" alt="长图">
        <span id="up"></span>
        <span id="down"></span>
    </div>
</body>

</html>